Linux File Management Commands
๐ vi, nano, touch, and cat Commands
โจ vi (Visual Editor)โ
vi
is a powerful text editor available in Unix/Linux systems. It has two main modes:
- ๐น Command mode: Used for navigation and issuing commands.
- ๐ Insert mode: Used for editing text.
๐ฅ Basic Commands:โ
vi filename
โ ๐๏ธ Open or create a file.- Press
i
โ โ๏ธ Switch to insert mode. - Press
Esc
โ ๐ Switch to command mode. :w
โ ๐พ Save file.:q
โ ๐ช Quit.:wq
orZZ
โ โ Save and quit.:q!
โ โ Quit without saving.
๐๏ธ nano (Simple Text Editor)โ
nano
is a user-friendly text editor with on-screen navigation.
๐ฅ Basic Commands:โ
nano filename
โ ๐๏ธ Open or create a file.CTRL + X
โ ๐ช Exit.CTRL + O
โ ๐พ Save file.CTRL + W
โ ๐ Search.CTRL + K
โ โ๏ธ Cut a line.CTRL + U
โ ๐ Paste a line.
๐ touch (Create Empty Files)โ
The touch
command is used to create an empty file or update the timestamp of an existing file.
๐ฅ Usage:โ
touch filename
โ ๐ Create a new empty file.touch file1 file2
โ ๐๐ Create multiple empty files.touch -t YYYYMMDDHHMM filename
โ โณ Change file timestamp.
๐ cat (Concatenate and View Files)โ
cat
is used to display, concatenate, and create files.
๐ฅ Usage:โ
cat filename
โ ๐ Display file content.cat file1 file2
โ ๐ Concatenate and display multiple files.cat > filename
โ ๐ Create a new file and enter content.cat filename1 >> filename2
โ โ Append content of one file to another.
๐ Differences Between vi, nano, touch, and catโ
๐ ๏ธ Command | ๐ฏ Purpose |
---|---|
๐ฅ๏ธ vi | Advanced text editor with modes and commands. |
โ๏ธ nano | Simple, user-friendly text editor. |
๐ touch | Creates an empty file or updates timestamps. |
๐ cat | Displays, concatenates, and creates files. |
These commands are essential for working with files in Linux and are commonly used in system administration and development workflows.
โก Advanced Commandsโ
โ๏ธ Command | ๐ Function |
---|---|
๐ฅ๏ธ vi | |
/search_term | ๐ Search for a term in the file. |
n | โญ๏ธ Jump to the next occurrence of the search term. |
N | โฎ๏ธ Jump to the previous occurrence of the search term. |
:%s/old/new/g | ๐ Replace all occurrences of 'old' with 'new'. |
:set nu | ๐ข Show line numbers. |
โ๏ธ nano | |
CTRL + W | ๐ Search for a term. |
CTRL + R | ๐ Replace text. |
CTRL + _ | ๐ฏ Jump to a specific line. |
ALT + U | โช Undo last action. |
ALT + E | ๐ Enable/Disable smooth scrolling. |
๐ touch | |
touch -c filename | ๐ซ Do not create a file if it doesnโt exist. |
touch -a filename | โณ Update only the access time. |
touch -m filename | โณ Update only the modification time. |
touch -d 'YYYY-MM-DD HH:MM:SS' filename | โฐ Set a specific timestamp. |
๐ cat | |
cat -n filename | ๐ข Display file content with line numbers. |
cat -s filename | ๐ซ Suppress repeated empty lines. |
cat -A filename | ๐ต๏ธ Show all hidden characters. |
cat < file1 > file2 | ๐ Redirect contents of file1 to file2. |
๐ Hope this helps in mastering these commands! ๐